package org.hagopa.games.moneypool.network;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class Reception {
	
	private List <NetClientHandler> waitingClients = new ArrayList<NetClientHandler>();
	private static Reception instance = new Reception();
	
	private  Reception()
	{
		System.out.println("Created Reception");
		
	}
	public int getWaitingClientsNo()
	{
		return this.waitingClients.size();
	}
	public void appendNewClient(NetClientHandler clnt)
	{
		if(null != clnt)
		{
//			boolean exists  = false;
//			Iterator<NetClientHandler> clItr = waitingClients.iterator();
//			while(clItr.hasNext() == true)
//			{
//				NetClientHandler tmp = clItr.next();
//				if(tmp.getClientId() == clnt.getClientId())
//				{
//					System.out.println("Already Exists!!! No: " + clnt.getClientId());
//					exists = true;
//				}
//				else if(clnt.getClientId() < 0)
//					return;
//			}
//			if(exists == false)
//			{
			if(validateClient(clnt) == true)
			{
				waitingClients.add(clnt);
				System.out.println("New Client appended");
			}
//			}
//			else
//			{
//				System.out.println("Already exists");
//			}
			
		}
	}
	private boolean validateClient(NetClientHandler clnt)
	{
		// check connected client for valid Id, valid game id and so on
		return true;
	}
	

	public static Reception getInstance()
	{
		if(null == instance)
		{
			instance = new Reception();
		}
		return instance;
	}
	
	public void setWaitingList(List<NetClientHandler> wcl)
	{
		this.waitingClients = wcl;
	
	}
	public Iterator<NetClientHandler> getIter()
	{
		return this.waitingClients.iterator();
	}
}
